package com.duan.config;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

/**
 * @author db
 * @version 1.0
 * @description UserInfoGenderConverter
 * @since 2024/7/2
 */
public class UserInfoGenderConverter implements Converter<Integer> {

    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String stringValue = cellData.getStringValue();
        switch(stringValue){
            case "男":
                return 0;
            case "女":
                return 1;
            default:
                return 2;
        }

    }

    @Override
    public WriteCellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        switch (value){
            case 0:
                return new WriteCellData<>("男");
            case 1:
                return new WriteCellData<>("女");
            default:
                return new WriteCellData<>("未知");
        }
    }
}
